package com.google.code.jbauble.dao;

import java.util.List;
import java.util.Map;

public interface Datastore {	
	<T> Key<T> getKey(T entity);

	Key<?> exists(Object keyOrEntity);
	
	/** Deletes the given entity (by id) */
	<T, V> int delete(Class<T> clazz, V id);
	/** Deletes the given entities (by id) */
	<T, V> int delete(Class<T> clazz, Iterable<V> ids);
	/** Deletes the given entities based on the query */
	<T> int delete(Query<T> q);
	/** Deletes the given entity (by @Id) */
	<T> int delete(T entity);

	/** Find all instances by type */
	<T> Query<T> find(Class<T> clazz);

	/** 
	 * <p>
	 * Find all instances by collectionName, and filter property.
	 * </p><p>
	 * This is the same as: {@code find(clazzOrEntity).filter(property, value); }
	 * </p>
	 */
	<T, V> Query<T> find(Class<T> clazz, String property, V value);
	
	/** 
	 * <p>
	 * Find all instances by collectionName, and filter property.
	 * </p><p>
	 * This is the same as: {@code find(clazzOrEntity).filter(property, value).offset(offset).limit(size); }
	 * </p>
	 */
	<T,V> Query<T> find(Class<T> clazz, String property, V value, int offset, int size);
	/** Saves the entities (Objects) and updates the @Id field */
	<T> Iterable<Key<T>> save(Iterable<T> entities);
	/** Saves the entities (Objects) and updates the @Id field */
	<T> Iterable<Key<T>> save(T... entities);
	/** Saves the entity (Object) and updates the @Id field */
	<T> Key<T> save(T entity);
	/** Returns a new query bound to the kind (a specific {@link DBCollection})  */
	<T> Query<T> createQuery(Class<T> kind);
	
	SqlNative getSqlNative();
}